package com.huayi.server.Controller.admin;

import com.huayi.server.Entity.CameraEntity;
import com.huayi.server.Forms.CameraForm;
import com.huayi.server.Repository.CameraRepostiory;
import com.huayi.server.Utils.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/admin/camera")
public class CameraManagerController {

    @Autowired
    CameraRepostiory repostiory;

    @Autowired
    Resp resp;

    @RequestMapping("list")
    public String list(Model model){
        List<CameraEntity> list = (List<CameraEntity>) repostiory.findAll();
        model.addAttribute("lists",list);
        return "admin/carema/list";
    }

    @RequestMapping("add")
    public String add(){
        return "admin/carema/add";
    }

    @RequestMapping(value = "addDo",method = RequestMethod.POST,consumes = "application/json")
    @ResponseBody
    public Resp adddo(@RequestBody CameraEntity entity){
        entity.setTime(new Date());
        repostiory.save(entity);
        resp.setCode(200);
        return resp;
    }
}
